package emulator.hardware.io.peripherals;

import java.util.LinkedList;

public class VicTapeContents {
	private LinkedList<VicTapeTrack> track_list = new LinkedList<VicTapeTrack>();
	private int current_index;
	
	public VicTapeContents()
	{
		current_index = 0;
	}

	public VicTapeTrack getCurrentTrack() {
		if (current_index < track_list.size())
			return track_list.get(current_index);
		return new VicTapeTrack();
	}

	public void addTrack(VicTapeTrack track) {
		long counter = 0;
		while (counter < track.getCount() && current_index < track_list.size())
		{
			counter += track_list.get(current_index).getCount();
			track_list.remove(current_index);
		}
		track_list.add(current_index, track);
		current_index++;
	}


	public int getCurrentIndex() {
		return current_index;
	}

	public int getTrackCount()
	{
		return track_list.size();
	}
	
	public void rewind()
	{
		if (current_index > 0)
			current_index--;
	}
	
	public void forward()
	{
		if (current_index < track_list.size())
			current_index++;
	}
}
